package com.blacktry.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.blacktry.entity.model.ApiResult;
import com.blacktry.entity.model.MenuRole;
import com.blacktry.mapper.MenuRoleMapper;
import com.blacktry.service.MenuRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blacktry.utils.ApiResultHandler;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author blackTry
 * @since 2021-06-25
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements MenuRoleService {

    @Override
    @Transactional
    public ApiResult<?> updateMenuRole(Integer rid, Integer[] mids) {
        this.baseMapper.delete(new QueryWrapper<MenuRole>().eq("role_id",rid));
        if(null==mids||0==mids.length){
            return ApiResultHandler.buildApiResult(200,"更新成功");
        }
        Integer result = this.baseMapper.insertRecord(rid, mids);
        if(result==mids.length){
            return ApiResultHandler.buildApiResult(200,"更新成功");
        }
        return ApiResultHandler.buildApiResult(-1,"更新失败");
    }
}
